using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSGPP.func
{
	public class frmPriceBaseConfig : Form
	{
		private Func objFunc = new Func();
		private int currID = 0;
		private IContainer components = null;
		private DataGridView dgvPriceBase;
		private Button btnTab3Save;
		private Button btnTab3Close;
		private Button btnUpdate;
		private Button btnAdd;
		private Button btnButton1;
		private Button button1;
		private Button button2;
		private Button button3;
		private Button btnDel;
		private DataGridViewTextBoxColumn Column7;
		private DataGridViewTextBoxColumn level1;
		private DataGridViewTextBoxColumn level2;
		private DataGridViewTextBoxColumn percent1;
		private DataGridViewTextBoxColumn percent2;
		private DataGridViewCheckBoxColumn Active;
		public frmPriceBaseConfig()
		{
			this.InitializeComponent();
		}
		private void frmPriceBaseConfig_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyData == Keys.Escape)
			{
				this.btnTab3Close.PerformClick();
			}
		}
		private void btnTab3Close_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmPriceBaseConfig_Load(object sender, EventArgs e)
		{
			this.getData();
		}
		private void getData()
		{
			SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
			sqlConnection.Open();
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("SELECT * FROM tabPriceBase", sqlConnection);
			DataSet dataSet = new DataSet();
			sqlDataAdapter.Fill(dataSet, "tabPriceBase");
			this.dgvPriceBase.DataSource = dataSet.Tables["tabPriceBase"];
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		private void btnUpdate_Click(object sender, EventArgs e)
		{
			this.dgvPriceBase.ReadOnly = false;
			this.btnTab3Save.Enabled = true;
		}
		private void btnTab3Save_Click(object sender, EventArgs e)
		{
			try
			{
				if (MessageBox.Show("Bạn muốn cập nhật quy định niêm yết giá ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
					for (int i = 0; i < this.dgvPriceBase.RowCount; i++)
					{
						if (this.dgvPriceBase.Rows[i].Cells["Active"].Value.ToString() == "True")
						{
							this.updatePriceBase(this.dgvPriceBase.Rows[i].Cells["Column7"].Value.ToString(), float.Parse(this.dgvPriceBase.Rows[i].Cells["level1"].Value.ToString()), float.Parse(this.dgvPriceBase.Rows[i].Cells["level2"].Value.ToString()), float.Parse(this.dgvPriceBase.Rows[i].Cells["percent1"].Value.ToString()), float.Parse(this.dgvPriceBase.Rows[i].Cells["percent2"].Value.ToString()), 1);
						}
						else
						{
							this.updatePriceBase(this.dgvPriceBase.Rows[i].Cells["Column7"].Value.ToString(), float.Parse(this.dgvPriceBase.Rows[i].Cells["level1"].Value.ToString()), float.Parse(this.dgvPriceBase.Rows[i].Cells["level2"].Value.ToString()), float.Parse(this.dgvPriceBase.Rows[i].Cells["percent1"].Value.ToString()), float.Parse(this.dgvPriceBase.Rows[i].Cells["percent2"].Value.ToString()), 0);
						}
					}
					this.dgvPriceBase.ReadOnly = true;
					this.btnTab3Save.Enabled = false;
					this.dgvPriceBase.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
					MessageBox.Show("Dữ liệu đã được cập nhật vào hệ thống!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				}
				this.btnDel.Enabled = true;
				this.dgvPriceBase.ReadOnly = true;
				this.dgvPriceBase.AllowUserToAddRows = false;
				this.btnTab3Save.Enabled = false;
			}
			catch
			{
				this.dgvPriceBase.ReadOnly = true;
				this.dgvPriceBase.AllowUserToAddRows = false;
				this.btnTab3Save.Enabled = false;
			}
		}
		public int updatePriceBase(string ID, float level1, float level2, float percent1, float percent2, int active)
		{
			int result;
			try
			{
				SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("sp_UpdatePricebase", sqlConnection);
				sqlCommand.CommandType = CommandType.StoredProcedure;
				sqlCommand.Parameters.Add("ID", SqlDbType.VarChar, 150);
				sqlCommand.Parameters.Add("Active", SqlDbType.Bit);
				sqlCommand.Parameters.Add("level1", SqlDbType.Float);
				sqlCommand.Parameters.Add("level2", SqlDbType.Float);
				sqlCommand.Parameters.Add("percent1", SqlDbType.Float);
				sqlCommand.Parameters.Add("percent2", SqlDbType.Float);
				try
				{
					sqlCommand.Parameters["ID"].Value = ID;
				}
				catch
				{
					sqlCommand.Parameters["ID"].Value = 0;
				}
				sqlCommand.Parameters["Active"].Value = active;
				sqlCommand.Parameters["level1"].Value = level1;
				sqlCommand.Parameters["level2"].Value = level2;
				sqlCommand.Parameters["percent1"].Value = percent1;
				sqlCommand.Parameters["percent2"].Value = percent2;
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				result = 0;
			}
			catch
			{
				result = 1;
			}
			return result;
		}
		private void btnAdd_Click(object sender, EventArgs e)
		{
			this.dgvPriceBase.AllowUserToAddRows = true;
			this.dgvPriceBase.ReadOnly = false;
			this.btnDel.Enabled = false;
			this.btnTab3Save.Enabled = true;
		}
		private void btnDel_Click(object sender, EventArgs e)
		{
			try
			{
				if (this.currID > 0)
				{
					if (MessageBox.Show("Bạn có chắc chắn muốn xoá mức niêm yết này không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
					{
						SqlConnection sqlConnection = new SqlConnection(this.objFunc.strConnectionString);
						sqlConnection.Open();
						SqlCommand sqlCommand = new SqlCommand("DELETE TabPriceBase WHERE [ID] = " + this.currID.ToString(), sqlConnection);
						sqlCommand.ExecuteNonQuery();
						sqlConnection.Close();
						sqlConnection.Dispose();
						this.getData();
					}
				}
			}
			catch
			{
			}
		}
		private void dgvPriceBase_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.currID = int.Parse(this.dgvPriceBase.Rows[e.RowIndex].Cells["Column7"].Value.ToString());
			}
			catch
			{
				this.currID = 0;
			}
		}
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle2 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle3 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle4 = new DataGridViewCellStyle();
			DataGridViewCellStyle dataGridViewCellStyle5 = new DataGridViewCellStyle();
			this.dgvPriceBase = new DataGridView();
			this.btnTab3Save = new Button();
			this.btnTab3Close = new Button();
			this.btnUpdate = new Button();
			this.btnAdd = new Button();
			this.btnButton1 = new Button();
			this.button1 = new Button();
			this.button2 = new Button();
			this.button3 = new Button();
			this.btnDel = new Button();
			this.Column7 = new DataGridViewTextBoxColumn();
			this.level1 = new DataGridViewTextBoxColumn();
			this.level2 = new DataGridViewTextBoxColumn();
			this.percent1 = new DataGridViewTextBoxColumn();
			this.percent2 = new DataGridViewTextBoxColumn();
			this.Active = new DataGridViewCheckBoxColumn();
			((ISupportInitialize)this.dgvPriceBase).BeginInit();
			base.SuspendLayout();
			this.dgvPriceBase.AllowUserToAddRows = false;
			this.dgvPriceBase.AllowUserToDeleteRows = false;
			this.dgvPriceBase.AllowUserToOrderColumns = true;
			this.dgvPriceBase.AllowUserToResizeColumns = false;
			this.dgvPriceBase.AllowUserToResizeRows = false;
			this.dgvPriceBase.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.dgvPriceBase.BackgroundColor = Color.White;
			this.dgvPriceBase.BorderStyle = BorderStyle.Fixed3D;
			this.dgvPriceBase.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.dgvPriceBase.ColumnHeadersVisible = false;
			this.dgvPriceBase.Columns.AddRange(new DataGridViewColumn[]
			{
				this.Column7,
				this.level1,
				this.level2,
				this.percent1,
				this.percent2,
				this.Active
			});
			this.dgvPriceBase.Cursor = Cursors.Hand;
			this.dgvPriceBase.Location = new Point(3, 25);
			this.dgvPriceBase.MultiSelect = false;
			this.dgvPriceBase.Name = "dgvPriceBase";
			this.dgvPriceBase.ReadOnly = true;
			this.dgvPriceBase.RowHeadersVisible = false;
			this.dgvPriceBase.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;
			this.dgvPriceBase.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
			this.dgvPriceBase.Size = new Size(510, 173);
			this.dgvPriceBase.TabIndex = 0;
			this.dgvPriceBase.CellEnter += new DataGridViewCellEventHandler(this.dgvPriceBase_CellEnter);
			this.btnTab3Save.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnTab3Save.BackColor = Color.FromArgb(192, 255, 255);
			this.btnTab3Save.Cursor = Cursors.Hand;
			this.btnTab3Save.Enabled = false;
			this.btnTab3Save.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnTab3Save.FlatStyle = FlatStyle.Flat;
			this.btnTab3Save.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnTab3Save.ImageAlign = ContentAlignment.MiddleLeft;
			this.btnTab3Save.Location = new Point(209, 202);
			this.btnTab3Save.Name = "btnTab3Save";
			this.btnTab3Save.Size = new Size(99, 26);
			this.btnTab3Save.TabIndex = 2;
			this.btnTab3Save.Text = "Ghi nhận";
			this.btnTab3Save.UseVisualStyleBackColor = false;
			this.btnTab3Save.Click += new EventHandler(this.btnTab3Save_Click);
			this.btnTab3Close.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnTab3Close.BackColor = Color.FromArgb(192, 255, 255);
			this.btnTab3Close.Cursor = Cursors.Hand;
			this.btnTab3Close.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnTab3Close.FlatStyle = FlatStyle.Flat;
			this.btnTab3Close.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnTab3Close.ImageAlign = ContentAlignment.MiddleLeft;
			this.btnTab3Close.Location = new Point(414, 202);
			this.btnTab3Close.Name = "btnTab3Close";
			this.btnTab3Close.Size = new Size(99, 26);
			this.btnTab3Close.TabIndex = 5;
			this.btnTab3Close.Text = "Thoát  [ESC]";
			this.btnTab3Close.UseVisualStyleBackColor = false;
			this.btnTab3Close.Click += new EventHandler(this.btnTab3Close_Click);
			this.btnUpdate.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnUpdate.BackColor = Color.FromArgb(192, 255, 255);
			this.btnUpdate.Cursor = Cursors.Hand;
			this.btnUpdate.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnUpdate.FlatStyle = FlatStyle.Flat;
			this.btnUpdate.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnUpdate.ImageAlign = ContentAlignment.MiddleLeft;
			this.btnUpdate.Location = new Point(106, 202);
			this.btnUpdate.Name = "btnUpdate";
			this.btnUpdate.Size = new Size(99, 26);
			this.btnUpdate.TabIndex = 3;
			this.btnUpdate.Text = "Cập nhật";
			this.btnUpdate.UseVisualStyleBackColor = false;
			this.btnUpdate.Click += new EventHandler(this.btnUpdate_Click);
			this.btnAdd.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnAdd.BackColor = Color.FromArgb(192, 255, 255);
			this.btnAdd.Cursor = Cursors.Hand;
			this.btnAdd.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnAdd.FlatStyle = FlatStyle.Flat;
			this.btnAdd.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnAdd.ImageAlign = ContentAlignment.MiddleLeft;
			this.btnAdd.Location = new Point(3, 202);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new Size(99, 26);
			this.btnAdd.TabIndex = 1;
			this.btnAdd.Text = "Thêm mới";
			this.btnAdd.UseVisualStyleBackColor = false;
			this.btnAdd.Click += new EventHandler(this.btnAdd_Click);
			this.btnButton1.BackColor = Color.FromArgb(255, 255, 192);
			this.btnButton1.FlatAppearance.BorderSize = 0;
			this.btnButton1.FlatStyle = FlatStyle.Flat;
			this.btnButton1.Location = new Point(3, 2);
			this.btnButton1.Name = "btnButton1";
			this.btnButton1.Size = new Size(208, 23);
			this.btnButton1.TabIndex = 17;
			this.btnButton1.Text = "Giá nhập trong khoảng";
			this.btnButton1.UseVisualStyleBackColor = false;
			this.button1.BackColor = Color.FromArgb(255, 255, 192);
			this.button1.FlatAppearance.BorderSize = 0;
			this.button1.FlatStyle = FlatStyle.Flat;
			this.button1.Location = new Point(212, 2);
			this.button1.Name = "button1";
			this.button1.Size = new Size(99, 23);
			this.button1.TabIndex = 18;
			this.button1.Text = "% Bán buôn";
			this.button1.UseVisualStyleBackColor = false;
			this.button2.BackColor = Color.FromArgb(255, 255, 192);
			this.button2.FlatAppearance.BorderSize = 0;
			this.button2.FlatStyle = FlatStyle.Flat;
			this.button2.Location = new Point(312, 2);
			this.button2.Name = "button2";
			this.button2.Size = new Size(99, 23);
			this.button2.TabIndex = 19;
			this.button2.Text = "% Bán lẻ";
			this.button2.UseVisualStyleBackColor = false;
			this.button3.BackColor = Color.FromArgb(255, 255, 192);
			this.button3.FlatAppearance.BorderSize = 0;
			this.button3.FlatStyle = FlatStyle.Flat;
			this.button3.Location = new Point(412, 2);
			this.button3.Name = "button3";
			this.button3.Size = new Size(101, 23);
			this.button3.TabIndex = 20;
			this.button3.Text = "Kích hoạt";
			this.button3.UseVisualStyleBackColor = false;
			this.btnDel.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnDel.BackColor = Color.FromArgb(192, 255, 255);
			this.btnDel.Cursor = Cursors.Hand;
			this.btnDel.FlatAppearance.BorderColor = Color.FromArgb(255, 128, 255);
			this.btnDel.FlatStyle = FlatStyle.Flat;
			this.btnDel.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnDel.ImageAlign = ContentAlignment.MiddleLeft;
			this.btnDel.Location = new Point(312, 202);
			this.btnDel.Name = "btnDel";
			this.btnDel.Size = new Size(99, 26);
			this.btnDel.TabIndex = 4;
			this.btnDel.Text = "Xoá bỏ";
			this.btnDel.UseVisualStyleBackColor = false;
			this.btnDel.Click += new EventHandler(this.btnDel_Click);
			this.Column7.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.Column7.DataPropertyName = "ID";
			dataGridViewCellStyle.Format = "D";
			dataGridViewCellStyle.NullValue = null;
			this.Column7.DefaultCellStyle = dataGridViewCellStyle;
			this.Column7.HeaderText = "ID";
			this.Column7.MinimumWidth = 100;
			this.Column7.Name = "Column7";
			this.Column7.ReadOnly = true;
			this.Column7.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.Column7.Visible = false;
			this.level1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.level1.DataPropertyName = "level1";
			dataGridViewCellStyle2.Alignment = DataGridViewContentAlignment.MiddleRight;
			this.level1.DefaultCellStyle = dataGridViewCellStyle2;
			this.level1.HeaderText = "Từ giá";
			this.level1.MinimumWidth = 97;
			this.level1.Name = "level1";
			this.level1.ReadOnly = true;
			this.level1.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.level1.Width = 97;
			this.level2.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.level2.DataPropertyName = "level2";
			dataGridViewCellStyle3.Alignment = DataGridViewContentAlignment.MiddleRight;
			dataGridViewCellStyle3.Font = new Font("Arial", 9.75f, FontStyle.Regular, GraphicsUnit.Point, 0);
			dataGridViewCellStyle3.ForeColor = Color.Black;
			this.level2.DefaultCellStyle = dataGridViewCellStyle3;
			this.level2.HeaderText = "Đến giá";
			this.level2.MinimumWidth = 110;
			this.level2.Name = "level2";
			this.level2.ReadOnly = true;
			this.level2.SortMode = DataGridViewColumnSortMode.NotSortable;
			this.level2.Width = 110;
			this.percent1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.percent1.DataPropertyName = "percent1";
			dataGridViewCellStyle4.Alignment = DataGridViewContentAlignment.MiddleRight;
			this.percent1.DefaultCellStyle = dataGridViewCellStyle4;
			this.percent1.HeaderText = "% Bán buôn";
			this.percent1.MinimumWidth = 100;
			this.percent1.Name = "percent1";
			this.percent1.ReadOnly = true;
			this.percent2.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.percent2.DataPropertyName = "percent2";
			dataGridViewCellStyle5.Alignment = DataGridViewContentAlignment.MiddleRight;
			this.percent2.DefaultCellStyle = dataGridViewCellStyle5;
			this.percent2.HeaderText = "% Bán lẻ";
			this.percent2.MinimumWidth = 100;
			this.percent2.Name = "percent2";
			this.percent2.ReadOnly = true;
			this.Active.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.Active.DataPropertyName = "Active";
			this.Active.HeaderText = "Sử dụng";
			this.Active.MinimumWidth = 100;
			this.Active.Name = "Active";
			this.Active.ReadOnly = true;
			this.Active.Resizable = DataGridViewTriState.True;
			this.Active.SortMode = DataGridViewColumnSortMode.Automatic;
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = Color.White;
			base.ClientSize = new Size(517, 231);
			base.Controls.Add(this.btnDel);
			base.Controls.Add(this.button3);
			base.Controls.Add(this.button2);
			base.Controls.Add(this.button1);
			base.Controls.Add(this.btnButton1);
			base.Controls.Add(this.btnAdd);
			base.Controls.Add(this.btnUpdate);
			base.Controls.Add(this.btnTab3Save);
			base.Controls.Add(this.btnTab3Close);
			base.Controls.Add(this.dgvPriceBase);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			//base.Icon = (Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			this.MaximumSize = new Size(533, 265);
			this.MinimumSize = new Size(533, 265);
			base.Name = "frmPriceBaseConfig";
			base.ShowInTaskbar = false;
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = " ..: Quy định khung giá bán";
			base.Load += new EventHandler(this.frmPriceBaseConfig_Load);
			base.KeyDown += new KeyEventHandler(this.frmPriceBaseConfig_KeyDown);
			((ISupportInitialize)this.dgvPriceBase).EndInit();
			base.ResumeLayout(false);
		}
	}
}
